package com.hd.appcommon.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hd.appcommon.entity.Door;
import com.hd.appcommon.entity.DoorVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import retrofit2.http.Url;

import javax.management.Query;
import java.util.List;

@Mapper
public interface DoorMapper extends BaseMapper<Door> {

    @Select("SELECT * from Door where FIND_IN_SET(door_id,(SELECT door_id_list from room where id=#{roomId})) ")
    List<DoorVo> getDoorList(String roomId);

    @Select("SELECT door_id from door ${ew.customSqlSegment} LIMIT 1")
    Integer exist(@Param("ew") QueryWrapper<Door> queryWrapper);

    @Update("update room set door_id_list = concat(door_id_list,',',#{doorId}) where id=#{roomId}")
    void addDoorId(Integer roomId, String doorId);

    @Select("SELECT door_id_list FROM room WHERE id = (SELECT room_id FROM door WHERE door_id = #{doorId} LIMIT 1) ")
    String getDoorIdListByDoorId(String doorId);

    @Update("UPDATE room set room.door_id_list = #{newDoorIdList} where room.id = (SELECT door.room_id as room_id FROM door where door.door_id = #{doorId})")
    void updateUserIdListByDoorId(String doorId, String newDoorIdList);
}
